//
//  Person.m
//  KVO
//
//  Created by gzjd on 2017/5/7.
//  Copyright © 2017年 gzjd. All rights reserved.
//

#import "Person.h"

@implementation Person
-(void)dealloc{
    [bankAcount release],bankAcount=nil;
    [super dealloc];
}
-(id)init{
    self=[super init];
    if(self){
        bankAcount=[[BankAcount alloc] init];
    }
    return self;
}
static void *OpeningBalance=(void *)&OpeningBalance;
-(void)registerAsObserver{
    [bankAcount addObserver:self forKeyPath:@"openingBalance" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:OpeningBalance];
    [bankAcount release];
}
-(void)unregisterObserver{
    [bankAcount removeObserver:self forKeyPath:@"openingBalance"];
    
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
    NSLog(@"key path %@,object %@,change %@",keyPath,object,change);
    if(context==OpeningBalance){
        NSString *v=[change objectForKey:NSKeyValueChangeNewKey];
    }else{
        
    }
}

@end
